package com.runjian.rundo.iot.agent.common.network.tcp.util;

import java.net.InetSocketAddress;
import java.net.SocketAddress;

import cn.hutool.core.util.StrUtil;

/**
 *
 * SocketAddress工具
 *
 * @author CaoQingHua
 */
public class SocketAddressUtil {

    private static String formatStr = "{}:{}";

    public static String formatAddress(SocketAddress socketAddress) {
        if (socketAddress instanceof InetSocketAddress) {
            InetSocketAddress inetSocketAddress = (InetSocketAddress)socketAddress;
            return StrUtil.format(formatStr, inetSocketAddress.getAddress().getHostAddress(), inetSocketAddress.getPort());
        } else {
            return StrUtil.EMPTY;
        }
    }

}
